home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000058_icon-group-sender _Mon Mar 3 12:31:17 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 3 Mar 1997 13:01:51 MST
  2. Date: Mon, 3 Mar 1997 12:31:17 -0600
  3. Message-Id: <199703031831.MAA09252@ns1.cmpu.net>
  4. Mime-Version: 1.0
  5. Content-Type: text/plain
  6. Content-Transfer-Encoding: 7bit
  7. From: gep2@computek.net
  8. Subject: Re: Help with Program
  9. To: icon-group@cs.arizona.edu
  10. X-Mailer: SPRY Mail Version: 04.00.06.17
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 1836
  14.  
  15. >> I thought about making something where you concatenate two consecutive lines 
  16. (in an overlapping pairs fashion) and then parse the two lines with a single 
  17. pattern match... eliminating the need to separately test the two category 
  18. numbers for equality, and eliminating all those "remember" assignments... but 
  19. finally decided that the way I did it was clearer and probably faster as well.
  20.  
  21. >That would have been an interesting solution to see!  
  22.  
  23. It's really pretty simple, too (although my original was probably more 
  24. efficient):
  25.  
  26.         &TRIM = 1
  27.     SWS = SPAN(" " CHAR(9))       ;* 'span whitespace' pattern
  28.     TAB = CHAR(9)                 ;* define a tab character
  29.     LET = ANY(&LCASE &UCASE)      ;* parse an alpha character
  30.     RECPAT = SPAN("0123456789") $ N SWS LET . M1A SWS LET . M2A SWS
  31. +      *N SWS LET . M1 SWS LET . M2 RPOS(0)
  32. RLOOP   (?(L1 = L) ?(LN1 = LN))       ;* remember prior line
  33.     L = INPUT ?(LN = LN + 1) :F(END)   ;* read and count line
  34.         (L1 " " L) ? RECPAT      :F(RLOOP) ;* parse line pair
  35.         OUTPUT = LN1 "-" LN TAB M1A M1 TAB M2A M2    :(RLOOP)
  36. END
  37.  
  38. This version unfortunately requires that the number appear in EXACTLY the same 
  39. form, although that could be fixed by changing *N to:
  40.      SPAN("0123456789") $ N2 *EQ(N,N2)
  41.  
  42. The bigger problem is that (since now you have two reasons for the pattern to 
  43. fail... either the line doesn't parse, or else the lines don't match) and that 
  44. you basically both lose the diagnostic message for malformed lines, and you 
  45. change the way the two surrounding (presuming they're good) lines are handled.
  46.  
  47. One could make it less possible to "fool" the pattern match by appending 
  48. something trickier than a space between the records (a CR/LF pair might work, 
  49. for example) and changing the pattern appropriately.
  50.  
  51. Gordon Peterson
  52. http://www.computek.net/public/gep2/
  53.  
  54.